<template>
	<view>
		<DangDang ref="dang" v-if="appStatus===1"></DangDang>
		<JiSuan v-if="appStatus===0"></JiSuan>
	</view>
</template>

<script>
	import DangDang from "@/components/dangledang.vue"
	import JiSuan from "@/components/jisuan.vue";
  import { shareTimeline , shareAppMessage } from "@/common/share.js";
  import store from "@/store/index.js"

	export default {
		data() {
			return {
				appStatus:""
			}
		},
		methods: {
			  getData() {
				return new Promise((resolve,reject)=>{
				  uni.request({
					url: store.state.ddhh, //仅为示例，并非真实接口地址。
					success: (res) => {
					  resolve(res.data)
					},
					fail:(err)=>{ 
					  reject(err)
					}
				  });
				})
			  }
    },
    onShow() {

    },
	components: {
		DangDang,JiSuan
	},
	onShareTimeline() {
    let random =  Math.floor(Math.random() * 4);  //0~3;
    return shareTimeline(random,this)
	},
    onShareAppMessage(res){
      let random =  Math.floor(Math.random() * 4);  //0~3;
      return shareAppMessage(random,this)
    },
	// #ifdef H5
		created(){
		  this.appStatus = 1;
		  console.log('h5')
		},
	// #endif
	// #ifdef MP
		async created(){
			let res = await this.getData()
      store.commit("setData",res)
			this.appStatus = res.setting.appStatus;
			console.log('小程序')
		},
	// #endif
	}
</script>

<style>

</style>
